package com.zjj.edu.system.service.impl;

import com.zjj.edu.common.constant.UserConstants;
import com.zjj.edu.common.utils.DateUtils;
import com.zjj.edu.common.utils.StringUtils;
import com.zjj.edu.system.domain.SysClassRoom;
import com.zjj.edu.system.mapper.SysClassRoomMapper;
import com.zjj.edu.system.service.ISysClassRoomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 教室Service业务层处理
 *
 * @author zjj
 * @date 2020-06-24
 */
@Service
public class SysClassRoomServiceImpl implements ISysClassRoomService
{
    @Autowired
    private SysClassRoomMapper sysClassRoomMapper;

    /**
     * 查询教室
     *
     * @param id 教室ID
     * @return 教室
     */
    @Override
    public SysClassRoom selectSysClassRoomById(Long id)
    {
        return sysClassRoomMapper.selectSysClassRoomById(id);
    }

    /**
     * 查询教室列表
     *
     * @param sysClassRoom 教室
     * @return 教室
     */
    @Override
    public List<SysClassRoom> selectSysClassRoomList(SysClassRoom sysClassRoom)
    {
        return sysClassRoomMapper.selectSysClassRoomList(sysClassRoom);
    }

    /**
     * 新增教室
     *
     * @param sysClassRoom 教室
     * @return 结果
     */
    @Override
    public int insertSysClassRoom(SysClassRoom sysClassRoom)
    {
        sysClassRoom.setCreateTime(DateUtils.getNowDate());
        return sysClassRoomMapper.insertSysClassRoom(sysClassRoom);
    }

    /**
     * 修改教室
     *
     * @param sysClassRoom 教室
     * @return 结果
     */
    @Override
    public int updateSysClassRoom(SysClassRoom sysClassRoom)
    {
        sysClassRoom.setUpdateTime(DateUtils.getNowDate());
        return sysClassRoomMapper.updateSysClassRoom(sysClassRoom);
    }

    /**
     * 删除教室对象
     *
     * @return 结果
     */
    @Override
    public int deleteSysClassRoomByIds(SysClassRoom sysClassRoom)
    {
        return sysClassRoomMapper.deleteSysClassRoomByIds(sysClassRoom);
    }

    @Override
    public String checkNameUnique(SysClassRoom vo) {
        Long id = StringUtils.isNull(vo.getId()) ? -1L : vo.getId();
        SysClassRoom info = sysClassRoomMapper.checkNameUnique(vo.getName(), vo.getCampusId());
        if (StringUtils.isNotNull(info) && info.getId().longValue() != id.longValue())
        {
            return UserConstants.NAME_NOT_UNIQUE;
        }
        return UserConstants.NAME_UNIQUE;
    }

    @Override
    public List<SysClassRoom> selectAllSysClassRoomList(long tenantId) {
        return sysClassRoomMapper.selectAllSysClassRoomList(tenantId);
    }
}
